#ifndef GAMEMANAGER_H
#define GAMEMANAGER_H

#include <QObject>
#include <QMessageBox>
#include "BoardColumn.h"
#include "ConnectFour.h"
#include "Animation.h"

#include <QDebug>

class GameManager : public QObject {

    Q_OBJECT

public:
    explicit GameManager(QObject *parent = 0);
    virtual void newGame();
    virtual void requestNewGame();
    virtual void requestUndo();

signals:
    void newGameStarted();
    void playerChanged(ConnectFour::Piece player);
    void needsAnimation(Animation::AnimationMode mode, int height, ConnectFour::Piece color);
    void columnNeedsUpdate(BoardColumn * column, int index);
    void winNeedsUpdate(ConnectFour::Win * win, ConnectFour::Direction direction, ConnectFour::Piece piece);
    void winPiece(ConnectFour::Piece piece);

public slots:
    virtual void requestMove(int index);
    virtual void addPieceToColumn(int index);
    virtual void finishAnimation(Animation::AnimationMode mode);

protected:
    ConnectFour::Piece getPiece(int column, int row);
    bool isAValidPiece(int column, int row);
    void checkDrawConditions();
    void checkWinConditions();
    void submitWin(ConnectFour::Direction direction, int column, int row, int consecutive);
    void columnAnimation(int index);
    void newGameAnimation();

    BoardColumn columns[NUM_COLUMNS];
    ConnectFour::Win wins[NUM_WINS];
    ConnectFour::Piece currentPlayer;
    int previousMoveIndex;
    bool isAnimating;

};

#endif // GAMEMANAGER_H
